package com.zst.sw.server.configuration;

import com.zst.sw.server.configuration.props.ConfigProperties;
import com.zst.sw.server.module.TraceDataHandler;
import com.zst.sw.server.network.GrpcServer;
import com.zst.sw.server.network.TraceSegmentReportServiceHandler;
import com.zst.sw.server.pipeline.DataPipelineProperties;
import com.zst.sw.server.pipeline.TraceSegmentDataPipeline;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@EnableConfigurationProperties({ConfigProperties.class, DataPipelineProperties.class})
@Configuration
public class SWGrpcServerInitializer {
    @Bean
    public TraceSegmentDataPipeline traceSegmentDataPipeline(DataPipelineProperties configProperties, TraceDataHandler traceDataHandler) {
        return new TraceSegmentDataPipeline(configProperties, traceDataHandler);
    }

    @Bean
    public TraceSegmentReportServiceHandler traceSegmentReportServiceHandler(TraceSegmentDataPipeline traceSegmentDataPipeline) {
        return new TraceSegmentReportServiceHandler(traceSegmentDataPipeline);
    }

    @Bean
    public GrpcServer grpcServer(ConfigProperties configProperties,
                                 TraceSegmentReportServiceHandler traceSegmentReportServiceHandler) {
        return new GrpcServer(configProperties, traceSegmentReportServiceHandler);
    }
}
